<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

<script>


  let tokenzier = (code) => {
    // 字符串下标
    let current = 0
    // 结果、词法列表
    let tokens = []

    let LETTERS = /[a-z|A-Z]/i
    while (current < code.length) {
      let char = code[current]
      if (LETTERS.test(char)) {
        let value = ''
        //英文字符字面量可能不是一个字符
        //索引我们循环知道不是英文字符
        while (LETTERS.test(char)) {
          value += char
          char = code[++current]
        }
        //push 一个词法、同时也是一个Json
        tokens.push({
          'type': 'name',
          value
        })

        current++
        continue
      }
      //操作符压入，等号是赋值操作
      if ('=' == char) {//let a = '=' //
        tokens.push({
          type: 'operator',
          value: char
        })
      }
      current++
      continue
    }//while end
    return tokens
  }//function end

  // 测试代码
  let simpleCode = `
        let a = 20
        println -> a
    `
  console.info(tokenzier(simpleCode))
</script>
</body>
</html>
